<div class="row changebox" style="height:1000px;">
    <div class="col-sm-12">
        <div id="tableedit_">
            <form id="addForm" action="{:U('Taskform/addForm')}" class="hidden" method="post">
                <div class="ruleTemplate">
                </div>
                <div class="ruleGroup form-inline hidden icheck">
                    <input class="groupType" type="hidden" name="groupType[]" value="checkbox"/>
                    <input name="groupName[]" maxlength="10" type="text" class="form-control groupInput" placeholder="请输入组名"/>
                    <label class="groupName hidden">
                        请输入组名
                    </label>
                    <label>
                        ：
                    </label>
                    <a href="javascript:void(0);" class="pull-right btn-type tooltips"  data-original-title="点击切换类型" title="点击切换类型" data-placement="top" data-toggle="tooltip" >
                        多选模式
                    </a>
                    <div class="groupIntro">
                        请在左侧选择规则
                    </div>
                    <i class="fa faicon icon-times" title="删除行"></i>
                    <!--<div class="fabg"></div>-->
                </div>
                
                
                <div style="padding:10px 0;" id="saveline">

                
                    <a class="btn-success btn btn-add" href="javascript:void(0);" >
                        <i class="fa icon-plus-square"></i>
                        <span>添加一行</span>
                    </a>

                    
                    
                    <button type="submit" class="btn btn-success" style="float:right; margin-left:10px;">保存</button>
                    <button type="button"  onClick="edittab(0);" class="btn btn-default" style="float:right;">取消</button>
                    
                    <html:dropdownselect class="memberselect" selected="" typelimit="1" listloaded="approverlistloaded" name="member" style="height:auto; display:inline-block; float:right; line-height:32px; margin-right:10px; width:120px;" multi="0" action="{:U('Team/membergroup')}" title="选择员工" placeholder="点击选择审核人" />
                    

                </div>
                <input type="hidden" name="ruleTemplate" id="ruleTemplate"/>
            </form>
            <div class="formTemplate hidden">
            </div>
        </div>
        <div id="logoptionbox">
            <div class="panel" style="margin-bottom:15px; box-shadow:none;" id="addTo"   data-position="bottom" data-intro="您可以在这里选择奖扣对象">
                <div class="panel-body row">
                    <div class="col-xs-6">
                        <html:dropdownselect typelimit="1" class="formMemberSelect" selected="" listloaded="memberListLoaded" name="formMember" style="height:auto; width:auto;" multi="0" action="{:U('Team/membergroup')}" title="选择员工" placeholder="点击选择奖扣分对象" />
                        <div id="formReselectLayout" style="top:0; display:none; left:0; bottom:0; right:0; position:fixed; z-index:4999;"></div>
                    </div>
                    <div class="col-xs-6">
                        <div class="icheck" id="formlist" name="about"  data-position="bottom" data-intro="请先选择奖扣类型">
                            <select class="form-control select-formcategory">
                                <option value="">点击选择奖扣类型</option>
                                <volist name="formcategorylist" id="vo">
                                    <option <?php if($vo['id']==$info['type_id']){echo('selected');} ?> value="{$vo.id}">{:getdeepstr($vo['cl'])}{$vo.name}</option>
                                </volist>
                            </select>
                            <div id="taskform" class="select-box">
                                <volist name="taskform" id="tf">
                                    <div class="square-red single-row source">
                                        <label for="source-{$i}">
                                            <input id="source-{$i}" type="radio" onchange=""  name="taskform" value="{$tf.id}"  />
                                            {$tf.title}
                                        </label>
                                    </div>
                                </volist>
                            </div>
                            <form id="taskformform" action="{:U('Taskform/getTaskform')}" method="post">
                                <input type="hidden" name="id" value=""/>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
            <div class="panel" id="myform" style="box-shadow:none;">
                <!--表结构-->
                <header></header>
                <div class="" style="height:200px;line-height:200px;text-align:center;vertical-align:middle;font-size:24px" data-position="top" data-intro="这里可以进行奖扣分项目">
                    <i class="fa icon-hand-o-up" style="color:#64CEA6;font-size:24px;vertical-align:middle" ></i> 请先选择加(减)分项目
                </div>
			<!--	<div style="padding-left:15px">
					注：<br/>
					1.奖扣对象是您希望被奖扣分的人<br/>
					2.选择奖扣类型，可以找到具体的事件类型<br/>
				</div>-->
            </div>
            
            <div class="panel hidden" id="sendBox" style="box-shadow:none;">
                <div class="panel-body">
                    <span class="pull-left" style="display: inline-block;line-height: 35px">审批人　：<span class="hidden" id="approvernametext">默认上级</span></span>
                    <div class="pull-left f-sele form-group">
                        <html:dropdownselect class="selectApprover" selected="" typelimit="1" listloaded="listloaded" name="man" style="height:auto; min-width:90px;width:auto;padding-left:12px;border: none;border-bottom: 1px solid #ddd;border-radius:0" multi="0" action="{:U('Team/membergroup')}" title="修改审批人" placeholder="修改审批人" />
                    </div>
                    <div class="icheck text-right" style="padding-top:9px;">
                        <div class="square-red single-row" style="display:inline; width:auto; float:right;">
                          <label><input type="checkbox" name="" id="parentSend" class="sall" value="" />
                          递交上级</label>
                        </div>
                        <div class="square-red single-row" style="display:inline; margin-right:40px; float:right; width:auto;">
                          <label><input type="checkbox" name="" id="tiketSend" class="sall" value="" />
                          发放奖票</label>
                        </div> 
                    </div>
                    <div class="row">
                    	<div class="col-xs-12">
                        	审批时间：<input class="form-control datepicker" id="createtime" name="createtime" readonly style="cursor:pointer; width:110px; display:inline;background-color: #fff;border: none;border-bottom: 1px solid #ddd;border-radius:0" value="<?php echo $sttime; ?>" placeholder="起始时间" type="text">
                        </div>
                    </div>
          		</div>
            
            </div>
        </div>
    </div>
</div>
<div id="integralrulebox">
    <div class="panel integralrule" style="display:none;">
        <div class="panel-body">
            <div class="row">
            
            
            
            <div class="col-sm-5"><form action="<?php echo U('Integral_rule/select');?>" method="post" id="selectdatalistform" >
            
            
            
                <div class="input-group m-bot15">
                    <input type="text" name="keywords" placeholder="输入关键词搜索" class="form-control">
                    <span class="input-group-btn">
                    <button type="submit" class="btn btn-default"><i class="fa icon-search" style="font-size:16px"></i></button>
                    </span>
                </div>
                
                
                
              
              
            </form></div>
                <div class="col-sm-4">
                    <html:dropdownselect class="typeselect1" selected="" name="type" style="height:auto; width:auto;" multi="0" action="{:U('Team/tree')}" title="选择分类"  placeholder="点击选择分类"  listloaded=""/>
                </div>
                
                
                
                
                
                <div class="col-sm-3">
                    <a href="javascript:void(0);" onClick="_openWindow('<?php echo U('Integral_rule/add') ?>',650,'新建规章制度','提交',null);" class="pull-right btn btn-success btn-block">
                        新建规章制度
                    </a>
                </div>
            </div>
            
            <br/>
            
            <div id="selectdatalist" class="box-fixed">
            </div>
            <div style="text-align:center; position:absolute; z-index:100; left:0; background:#fff; bottom:0px; width:100%;" id="selectdatalistpages">
            </div>
        </div>
    </div>
</div>
<script>
var integralrule = $('.integralrule');
$("#selectdatalist").ajaxlist();
$("#taskform").ajaxlist({success:function(obj){
	
}});
$('.wbg').removeClass('wbg');
$('.trfooter.hidden').removeClass('hidden');
//检测如果有表格和有选择员工的话则将员工ID和名字加入表单中
function checkMember(e){
	if($("#myform form").length&&$(".formMemberSelect.binded .itemspan").length){
		$("#myform form input[name='member_id']").remove();
        $("#myform form input[name='member_name']").remove();
		if($('.formMemberSelect .itemspan input').length){
        	$('#myform form').append("<input type='hidden' name='member_id' value='"+$('.formMemberSelect .itemspan').children("input:eq(1)").attr('value')+"'><input type='hidden' name='member_name' value='"+$('.formMemberSelect .itemspan').children("input:eq(0)").attr('value')+"'>");	
		}
	}
}
function listloaded(){
	$('.selectApprover').blur(function(){
		$("#myform form input[name='approver']").remove();
		$("#myform form input[name='approvername']").remove();
		if($('.selectApprover.binded .itemspan').children('input:eq(1)').length!=0){
			$('#myform form').append("<input type='hidden' name='approver' value='"+$('.selectApprover .itemspan').children("input:eq(1)").attr('value')+"'><input type='hidden' name='approvername' value='"+$('.selectApprover .itemspan').children("input:eq(0)").attr('value')+"'>");
			$('#approvernametext').text($('.selectApprover .itemspan').children("input:eq(0)").attr('value'));
		}else{
			$('#myform form').append("<input type='hidden' name='approver' value=''><input type='hidden' name='approvername' value=''>");
		}
	});
}
//选择员工
function memberListLoaded(){ 
    $('.selectitem').click(function(){
        if($(this).prev('em').length!=0){
			$(this).prev('em').click();
            $(this).find('input').eq(0).attr('name','pos_name');
            $(this).find('input').eq(1).attr('id','pos_id');
        }else{
			//console.log($(this).find('input'));
            $(this).find('input').eq(0).attr('name','member_name');
            $(this).find('input').eq(1).attr('name','member_id');
        }
    });
    $('.formMemberSelect').blur(checkMember);
}
//当点击选择的事件的时候
$(".select-formcategory").change(function(e) {
    $("#taskformform input").val($(this).val());
	$("#taskformform").submit();
	$(".select-box").show();
});
$(".select-box").change(function(e) {
	var value=$(this).find(":checked").val();
	var text=$(this).find('input[value="'+value+'"]').parents('label').text();
	var tag_a='<a class="pull-right" onclick="getformedit('+value+');" href="javascript:void(0);">修改当前表格</a>';//'
	tag_a=tag_a.replace('remind',value);
	//检测员工ID
	$("#myform header").remove();
	//在表单加载完成之后，添加标题的重要隐藏域。
	//此处做法不对，100ms内无法加载完成就会失败。
	/*setTimeout(function(){ 
    	checkMember();
		$("#myform").prepend('<header class="panel-heading">'+text+tag_a+'</header>');
		$("#f-form1 form").append('<input type="hidden" name="access" value="Integral_log"/>');	
	},100);*/
	$(this).hide();
});

$(window).trigger('load');
</script>
<style>
/*选择事件的样式*/
.select-box{ display:none; padding:10px; position:absolute; width:90%; box-shadow:1px 2px 8px rgba(0,0,0,0.22); background:#fff; z-index:2;}
/*表格选择人员时的样式*/
.seleBox{position:absolute; right:140px; top:19px; padding:1px 24px;  display:inline-block; border:none;}
.seleIcon{position:absolute; border-radius:20px; font-size:10px; font-weight:bold; top:4px; right:4px; background:#aaa; display:block; width:16px; height:16px; line-height:16px; text-align:center; color:#fff;z-index:2;}
.seleText{ display:none;}
.selectlist{margin:0; padding:0;}
.selectlist li{list-style-type:none; margin:0; padding:0;padding:5px; border-bottom:1px solid #eee; margin:0 8px;}
.selectlist li:hover{background:#eee;}
</style>
<style>
	#tableedit_ .formTemplate{ position:relative; padding:10px; margin:10px 0; }
	#tableedit_ .cover{ height:100%; width:100%; position:absolute; cursor: not-allowed; bottom:0; right:0;border: 1px dashed #eee;}
	#tableedit_ .cover:hover{ background:rgba(0,0,0,0.01);}
    #tableedit_ .panel-rightMenu{ box-shadow:4px 4px 5px rgba(0,0,0,0.2); border:1px solid #ddd; border-radius:2px;position: fixed;width: 250px; z-index:999; color:#333; display:none;}
    #tableedit_ .panel-rightMenu li{ padding-left:20px; padding-top:6px; padding-bottom:6px; font-size:12px;}
   #tableedit_ .panel-rightMenu li:hover{ background:#eee; cursor:pointer;}
	#tableedit_ .panel-fixed{ position:fixed;}
	#tableedit_ .box-fixed{ overflow:auto; padding-right:10px;}
	#tableedit_ .f-choiceMember { margin-top:5px;}
	#tableedit_ .f-addFormBox{ display:none;}
	/*规则表单的样式*/
	#tableedit_ .form-square{ border:1px solid #ddd !important;}
	#tableedit_ .color-main{ border-color:#65cea7;}


	#tableedit_ .panel-form .panel-body{ min-height:500px; position:relative;}
	#tableedit_ .panel-form .btn-type{position: absolute;right: 0;top: 3px;box-shadow: 0 1px 4px rgba(0,0,0,0.14); font-size:12px;z-index: 4;}

	#tableedit_ .panel-form .btn-preview{ right:10px; bottom:10px; position:absolute;}
	#tableedit_ .panel-form .btn-submit{ right:90px; bottom:10px; position:absolute;}
	#tableedit_ .panel-form input.form-control{ border:none; border-bottom:1px solid #eee; border-radius:0; background:none;-webkit-box-shadow: 0 0 0px 1000px white inset;    -webkit-appearance:none;}
	#tableedit_ .panel-form .form-control:focus{ border-color:#65cea7 !important;}
	#tableedit_ .panel-form .bottomLine{ position:absolute; bottom:5px; width:50%;}
	#tableedit_ .panel-form .single-row{ position:relative;}
	/*规则组.text-big{width: inherit;display: inline-block;border-radius: 2px;text-align: center; background:#f5f5f5; padding:15px; cursor:pointer; border:1px solid #f5f5f5; margin-top:5px; transition:0.1s ease-in-out all;}*/
	#tableedit_ #addForm{ background-color:rgba(0,0,0,0.00);}
	#tableedit_ .text-big{ margin-right:15px; margin-top:15px;}
	#tableedit_ .text-big.btn-danger{color: #666;background-color: #fff;border-color: #ddd;}
	#tableedit_ .text-big.btn-danger:hover{color: #fff;background-color: #d2322d;border-color: #ac2925;}
	#tableedit_ .text-big.btn-default:hover{ border:1px solid #ddd; background:#65cea7; color:#fff;}
	#tableedit_ .text-big:active{ background:#e2e2e2;}
	#tableedit_ .sourceInput{ max-width:60px; margin-bottom:5px;}
	.sourcePanel{text-align: center;position: absolute;top: 20px;background: #fafafa;border: 1px solid #ddd;padding: 5px; display:none; z-index:3;}
	#tableedit_ .SelectDataListItem{ border-bottom:1px solid #eee;}
	#tableedit_ .ruleGroup{border:1px solid #eee;min-height:50px; position:relative; margin-bottom:0px; margin-top:0px; padding:0px;  cursor:pointer; padding-left:10px; background-color:#fff;min-height: 59px;}
	#tableedit_ .ruleGroup > *{ margin-top:10px !important; margin-bottom:10px;}
	#tableedit_ .ruleGroup .groupInput{width:110px;}
	
	#tableedit_ .ruleGroup .groupIntro{height: 30px; width: 50%;position: absolute; padding:7px; margin:auto; top:0; bottom:0; left:0; right:0; text-align:center; color:#ddd;}
	
	/*切换选择*/
	.ruleGroup  a{margin-right:20px; display:none; font-weight:normal; line-height:30px; color:#65cea7; width:60px; border-radius:2px; text-align:center; background:#fff; margin-top:3px;}
	#tableedit_ .ruleGroup a:hover{ background:#65cea7; color:#fff;}
	#tableedit_ .ruleGroup:hover{ border:1px dashed #aaa;}
	/*规则（组）删除按钮*/
	#tableedit_ .ruleGroup > .faicon{position: absolute;z-index: 3;right: 3px;top:-7px;font-size: 16px;color: #65cea7; display:none; cursor:pointer;}
	#tableedit_ .ruleGroup .fabg{position: absolute;top: 0;z-index: 2;right: 0;border: 16px solid #65cea7;border-left-color: rgba(0,0,0,0.00);border-bottom-color: rgba(0,0,0,0.00); display:none;}
	#tableedit_ .ruleGroup>label{ margin-left:0px; position:relative; padding-right:10px; padding-top:5px; padding-left:10px; background-color:inherit;}
	#tableedit_ .ruleGroup>label .faicon{ position:absolute; right:3px; top:0px; color:#65cea7; display:none; cursor:pointer;}
	#tableedit_ .ruleGroup>label:hover .faicon{ display:block;}
	#tableedit_ .ruleGroup>.item:hover{ outline:1px dashed #65cea7; outline-offset:0px;}
	#tableedit_ .intePanel{position: absolute;padding: 6px;background: white;white-space: nowrap;left: 0; top:100%;font-size: 12px;z-index: 	1;box-shadow: 0px 1px 4px rgba(0,0,0,0.14); display:none;}
	#tableedit_ .ruleGroup>.item:hover .intePanel{ display:block;}
	/*选择状态*/
	#tableedit_ .ruleGroup.selected{ border-left:5px solid #65cea7; background:#fafafa;}
	#tableedit_ .ruleGroup.selected > .faicon,.ruleGroup.selected .fabg,.ruleGroup.selected a{  display:block}
	#tableedit_ .ruleGroup.selected input.form-control{ border-bottom:1px solid #65cea7;}
	
	#tableedit_ .aui_main{ vertical-align:top;}
	#tableedit_ .f-choiceMember label{ padding:8px 0;}
	#tableedit_ .f-choiceMember .f-sele{ position:absolute; top:-10px; left:100%; white-space:nowrap;}
	#tableedit_ .ui-sortable-placeholder {border: 4px dotted #eee;visibility: visible !important; background-color:rgba(255,255,255,0.3);}
	.aui_content #tableedit_ .form-inline{width:100%;}
	.aui_content #tableedit_ .form-inline .form-control.groupInput{margin-left:10px;}
	.wbg{background:#fff;}
</style>
<script>
//表单验证
	$("#addForm").Validform({
		ajaxPost:true,
		tiptype:function(){
			return false;	
		},
		beforeCheck:function(obj){
			//检查是否有字段未填写
			if($(".ruleGroup").eq(-2).find(".groupInput").val()==''){
				$.ThinkBox.error('请将内容填写完整！',{'delayClose':1000,modal:false, 'close': '关闭',x:0,y:0,center:false,locate:['left','top'], show:['',0]});
				$(".ruleGroup").eq(-2).find(".groupInput").focus();
				return false;
			}
			//$(".btn-preview").click();
			//序列化字段的名称
			$("#addForm .ruleGroup").removeClass("selected");
			$(obj).find(".ruleTemplate .ruleGroup").each(function(index, element) {
                $(element).find('.checkbox').each(function(i,e){
					$(e).attr('name','groupRule['+index+']['+i+'][0]');
					$(e).siblings('.sourceInput').attr('name','groupRule['+index+']['+i+'][1]');
				});
            });
			//填充模板的内容
			var html='';
			$(".groupInput").each(function(index, element) {
                $(this).attr('value',$(this).val());
            });
			html=$(".ruleTemplate").html();
			$("#ruleTemplate").val(html);
		},
		callback:function(data){
			$(".formTemplate").html('');
	        $(".ruleTemplate").html('');
			$.ThinkBox.success('提交成功',{'delayClose':1000,modal:false, 'close': '关闭',x:0,y:0,center:false,locate:['left','top'], show:['',0]});
			
			edittab(0);
		}
	});
	function edittab(t){
		if(t == 0){
			$('.trfooter').removeClass('hidden');
		    $('#addForm').addClass('hidden');
			$('#logoptionbox').removeClass('hidden');
			$('.formTemplate').addClass('hidden');
			$('.aui_content').removeClass('wbg');

	        var value=$(".select-box").find(":checked").val();
			var text=$(".select-box").find('input[value="'+value+'"]').parents('label').text();
			$.get('<?php echo U('Taskform/getnewform'); ?>',{id:value},function(data){
				$('#myform').html(data.tbody);
				var tag_a='<a class="pull-right" onclick="getformedit('+value+');" href="##"><i class="fa icon-edit"></i> 修改当前表格</a>';//'
	
				tag_a=tag_a.replace('remind',value);
				//添加标题
				$("#myform header").remove();
				setTimeout(function(){checkMember(); $("#myform").prepend('<header class="panel-heading">'+text+tag_a+'</header>');},100);
				
				
				
				
				
			
				$(".checkoutform .square-red input").on('ifChecked', function(event){
		$(this).trigger('change');
	});
	$(".checkoutform .square-red input[type='checkbox']").on('ifUnchecked', function(event){ //如果不选中，点击后则为选中
		$(this).trigger('change');
	});
	$('.checkoutform .square-red input').each(function(index, element) {
        $(this).change(function(e) {

			$(this).parent().parent().next().find('*').removeClass('hidden pull-left pull-right');
			$('.checkoutform .sourcePanel input').attr('disabled', 'disabled');
			$(this).parent().parent().next().find('input').removeAttr('disabled');
			var input = $(this).parent().parent().next().removeClass('hidden').html();
			if('' != $(this).parent().parent().parent().parent().attr('title')){
				var html = '<div class="alert alert-warning fade in id'+$(this).val()+'">'+$(this).parent().parent().parent().parent().attr('title')+'&nbsp;&nbsp;'+input+'</div>';
			}else{
				var html = '<div class="alert alert-warning fade in id'+$(this).val()+'">无 &nbsp;&nbsp;'+input+'</div>';
			}
			if($(this).attr('type') == 'radio'){
				$('.checkoutform .alert.alert-warning.fade.in').remove();
			    $(this).parent().parent().parent().parent().parent().after(html);
			}
			
			
			if($(this).attr('type') == 'checkbox'){
				if($(this).prop('checked')){
					$(this).parent().parent().parent().parent().parent().after(html);
				}else{
					$('.checkoutform .alert.alert-warning.fade.in.id'+$(this).val()).remove();
				}
			}
        });
    });
				
				
				
				
				
				
				
				
				//渲染ICHECK
			$('#myform .square-red input').iCheck({
				checkboxClass: 'icheckbox_square-red',
				radioClass: 'iradio_square-red',
				increaseArea: '20%'
			});
			}, 'json');
		}else{
			$('.aui_content').addClass('wbg');
			$('.trfooter').addClass('hidden');
		    $('#addForm').removeClass('hidden');
			$('#logoptionbox').addClass('hidden');
			$('.formTemplate').removeClass('hidden');
		}
	}
	
	
	
	
//当点击通用模板时，表单中显示出模板的表单内容
	function getformedit(dataId) {
		$('#logoptionbox').addClass('hidden');
		$.getJSON('{:U('Taskform/getTemp')}',{'id':dataId},function(data){
			if(data.status){
				$("#addForm input[name='id']").remove();
				edittab(1);

				if(Number(data.approver)){
					$(".iradio_square-red:eq(1)").click();
					$(".f-sele>div").html('<span class="itemspan">'+data.approvername+'</span>');
				}
				$("#addForm").append('<input type="hidden" name="id" value="'+data.id+'"/>');
				$(".btn-preview").removeClass("btn-success").addClass("btn-danger").text('修改表格');

				//填充表单数值
				if(data.ruleTemplate!=''){
					$(".ruleTemplate").html(data.ruleTemplate);
					//$(".ruleTemplate .ruleGroup:eq(0)").click();
				}else{
					$(".ruleTemplate").html('');
					$(".btn-add").click();
				}
				if(data.template!=''){
					$(".formTemplate").html(data.template).append('<div class="cover"></div>');
				}else{
					$(".formTemplate").html('');
				}
				$("#name").val(data.name);
				$("#formcategory_id").val(data.formcategory_id);
				$(data.tbody).each(function(index, element) {
					$("#addForm .groupInput").eq(index).removeClass('hidden').val(element.name);
				});
				$("#addForm .ruleGroup:not(:last)").removeClass('hidden').find('.groupInput').removeClass('hidden');
				$(".ruleTemplate").sortable();
			}
		});
    
    }
	//当有一点规则组被选择的时候给一个选择的状态
	$("#addForm").on("click",".ruleGroup",function(){
		$(".SelectDataListItem").removeClass("selected");
		integralrule.appendTo('#integralrulebox');
		integralrule.hide(10);
		$('#saveline').show();
		if($(this).hasClass("selected")){
			$(".ruleGroup").removeClass("selected");
			
		}else{
			$(".ruleGroup").removeClass("selected");
			$(this).addClass("selected");
			//给左边的规则加上选择的状态
			integralrule.insertAfter('.ruleGroup.selected');
			integralrule.show(100);
			$('#saveline').hide();
			
			$(this).find(".item").each(function(index, element) {
				$(".SelectDataListItem."+$(this).attr('data-target')).addClass('selected');
            });
		}
		
	});
	//当点击关闭的时候
	$("#addForm").on("click",".faicon",function(e){
		e.stopPropagation();
		if(confirm('确定删除？')){
			$(this).parent().remove();	//.parents(".ruleGroup")
		}
	});
	
	
	//取消表单的点击事件
	$("#addForm").on("click","input",function(e){
		var e=e||window.event;
		if(e.stopPropagation) {   
			e.stopPropagation();  
		} else {  
			e.cancelBubble = true; 
		}
		if(!$(this).parents(".ruleGroup").hasClass('selected')){
			//$(".ruleGroup.selected").removeClass("selected");
			$(this).parents(".ruleGroup").click();
		}
	});
	//点击切换单/多选
	$("#addForm").on("click",".btn-type",function(e){
		var e=e||window.event;
		if(e.stopPropagation) {   
			e.stopPropagation();  
		} else {  
			e.cancelBubble = true; 
		} 
		var obj=$(this).parents(".ruleGroup");
		if(obj.find(".groupType").val()=='radio'){
			obj.find("input[name='1']").attr('type','checkbox');
			obj.find('.groupType').val('checkbox');
			obj.find('.radio div').attr('class','icheckbox_square-red');
			obj.find('.radio').removeClass('radio').addClass('checkbox');
			obj.find(".btn-type").html('多选模式');
		}else {
			obj.find("input[name='1']").attr('type','radio');
			obj.find('.groupType').val('radio');
			obj.find('.checkbox div').attr('class','iradio_square-red');
			obj.find('.checkbox').removeClass('checkbox').addClass('radio');
			obj.find(".btn-type").html('单选模式');
		}
	});
	//当点击添加行的时候
	$(".btn-add").click(function(){
		if($(".ruleGroup").eq(-2).find(".groupInput").val()!=''||$(".ruleGroup").length<2){
			$(".ruleGroup.hidden").clone().removeClass("hidden").appendTo($(".ruleTemplate"));
			$(".ruleGroup").eq(-2).click();
			$(".ruleTemplate").sortable();
		}else{
			$(".ruleGroup").eq(-2).find(".groupInput").focus();
			$.ThinkBox.error('请填写完内容后添加 ',{'delayClose':1000,modal:false, 'close': '关闭',x:0,y:0,center:false,locate:['left','top'], show:['',0]});	
		}
	});
	//当规则被点击的时候，在区域中创建选项
	$("#selectdatalist").on("click",".SelectDataListItem ",function(){
		var obj=$(this).find(".sourceList");
		if($("#addForm .ruleGroup.selected").find("."+obj.attr("data-source")).length){
			$("#addForm .ruleGroup.selected").find("."+obj.attr("data-source")).remove();
		}else{
			$("#addForm .ruleGroup.selected").append(obj.html()).find(".groupIntro").remove();
		}
		$(this).toggleClass("selected");
		if($("#addForm .ruleGroup.selected").length==0){
			$.ThinkBox.error('请选择行',{'delayClose':1000,modal:false, 'close': '关闭',x:0,y:0,center:false,locate:['left','top'], show:['',0]});	
			$(this).removeClass("selected");	
		}
	});
	
	
	$('.typeselect1').blur(function(){
            $("#selectdatalistform input[name='type_id']").remove();
            if($('.typeselect1 .itemspan').children('input:eq(1)').length!=0){
                $('#selectdatalistform').append("<input type='hidden' name='type_id' value='"+$('.typeselect1 .itemspan').children("input:eq(1)").attr('value')+"'>");
            }
            $('#selectdatalistform').submit();
			$('.square-red input').iCheck({
				checkboxClass: 'icheckbox_square-red',
				radioClass: 'iradio_square-red',
				increaseArea: '20%'
			});
        });
	
	
	setTimeout(function(){ $('.changebox').css('height','auto'); }, 1000);
	
	
	//奖票、递交上级
	$('#sendBox #parentSend').change(function(e) {
		var html = '<input type="hidden" class="sendparentid" name="send" value="1">';
		if($(this).prop('checked')){
			$(html).appendTo('#f-form1 form.checkoutform');
		}else{
			$('#f-form1 form.checkoutform .sendparentid').remove();
		}
    });
	$('#sendBox #tiketSend').change(function(e) {
        var html = '<input type="hidden" class="sendticketid" name="ticket" value="1">';
		if($(this).prop('checked')){
			$(html).appendTo('#f-form1 form.checkoutform');
		}else{
			$('#f-form1 form.checkoutform .sendticketid').remove();
		}
    });
	$('#sendBox #createtime').change(function(e) {
        var html = '<input type="hidden" class="createtime" name="createtime" value="'+$(this).val()+'">';
		if($(this).val()){
			$(html).appendTo('#f-form1 form.checkoutform');
		}else{
			$('#f-form1 form.checkoutform .starttime').remove();
		}
    });
	
	
	
	function approverlistloaded(){
	$('.selectitem').click(function(){
		
		$(this).find('input').eq(0).attr('name','approvername');
		$(this).find('input').eq(1).attr('name','approver');
	});
	$('.memberselect').blur(function(){
		$("#addForm input[name='approver']").remove()
		$("#addForm input[name='approvername']").remove();
		var id=$('.memberselect .itemspan').children("input:eq(1)");
		var name=$('.memberselect .itemspan').children("input:eq(0)");
		id.attr('name','approver');
		name.attr('name','approvername');
		$('#addForm').append("<input type='hidden' name='"+id.attr('name')+"' value='"+id.attr('value')+"'><input type='hidden' name='"+name.attr('name')+"' value='"+name.attr('value')+"'>");
	});
}
	
	
	
</script>
